package com.ecommerce.dal.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.ecommerce.dal.dao.IAdminDAO;
import com.ecommerce.dal.entity.Admin;
import com.ecommerce.dal.util.CustomHibernateDAOSupport;

@Repository("adminDAO")
public class AdminDAO extends CustomHibernateDAOSupport implements IAdminDAO {

	@Override
	public void save(Admin admin) {
		getHibernateTemplate().save(admin);

	}

	@Override
	public void update(Admin admin) {
		getHibernateTemplate().update(admin);

	}

	@Override
	public void delete(Admin admin) {
		getHibernateTemplate().delete(admin);

	}

	@Override
	public Admin findByAdminId(long adminId) {
		List list = getHibernateTemplate().find(
				"from Admin admin where ADMIN_ID=?", adminId);
		return (Admin) ((list != null && list.size()>0) ? list.get(0) : null) ;
	}

	@Override
	public Admin findVerifiedAdmin(String userName, String password) {
		List list = getHibernateTemplate()
				.find("select admin from Admin admin inner join admin.user user where user.userName = ? and user.password = ?",
						userName, password);
		return (Admin) ((list != null && list.size()>0) ? list.get(0) : null) ;
	}

}